package com.zhaotianhao.check.comboserver.controller;

import com.zhaotianhao.check.comboserver.common.JsonResult;
import com.zhaotianhao.springboot.fileupload.common.FileResult;
import com.zhaotianhao.springboot.fileupload.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author Z-7
 * @Date 2022/3/31
 */
@CrossOrigin
@RestController
@RequestMapping("file")
public class FileController {
    @Autowired
    private FileService fileService;

    @PostMapping("upload")
    public JsonResult upload(MultipartFile file){
        FileResult fileResult = fileService.uploadFile(file);
        if(fileResult != null){
            return JsonResult.successd(fileResult);
        }
        return JsonResult.faild("上传失败");
    }
}
